/*
  (C) 2005 Adam D. Bradley

  This program is free software; you can redistribute it and/or
  modify it under the terms of Version 2 of the GNU General Public 
  License.
  
  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  General Public License for more details.
  
  You should have received a copy of the GNU Library General Public
  License along with this library; if not, write to the Free
  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

package step;

import java.util.ArrayList;

import step.exceptions.STEPException;


public abstract class AbstractTrigger extends Node
{
	public static final int ASLEEP = 0;
	public static final int PROCESSING = 1;
	public static final int TESTING = 2;
	public static final int EDGEWAITING = 3;
	public static final int DONE = 4;

	protected int state;

	public static final String StateName(int state) {
		switch(state) {
		case ASLEEP:
			return "ASLEEP";
		case PROCESSING:
			return "PROCESSING";
		case TESTING:
			return "TESTING";
		case EDGEWAITING:
			return "EDGEWAITING";
		case DONE:
			return "DONE";
		default:
			assert(false);
		}
		return "Unknown";
	}

	public AbstractTrigger(String id) {
		super(id);
		state = ASLEEP;
	}

	public AbstractTrigger() {
		super();
		state = ASLEEP;
	}

	public String GetInfoXML() {
		return super.GetInfoXML(
			"<state>" + StateName(state) + "</state>");
	}

	// this code is added by Ray
	//	 MODIFIES: compilationErrors 
	// EFFECT: checks if a Trigger has exavtly 2 children, if not it adds an exception to compilationErrors

	public void validate(Graph g, ArrayList<STEPException> compilationErrors) {
		if (children.length != 2) {
			compilationErrors.add(new step.exceptions.IllegalChildException("Node "
					+ this.GetID()
					+ " :A trigger Should have exactly 2 Children"));
			}
		}
}
